package cn.zz.veggie.application.helper;

import java.util.Objects;

import cn.zz.comm.exception.BizException;
import cn.zz.veggie.core.enums.exception.Biz403Error;
import cn.zz.veggie.model.domain.Order;
import cn.zz.veggie.model.domain.OrderInfo;

/**
 * @author zhongq
 * @since 2024/6/3
 */
public class OrderHelper {
	public static void requireNoNull(Order order, String sn) {
		if (order == null) {
			throw new BizException(Biz403Error.ORDER_NOT_FOUND, sn);
		}
	}

	public static void requireNoNull(Order order, Integer id) {
		if (order == null) {
			throw new BizException(Biz403Error.ORDER_NOT_FOUND, id);
		}
	}

	public static void requireNoNull(OrderInfo item, Integer id) {
		if (item == null) {
			throw new BizException(Biz403Error.ORDER_ITEM_NOT_FOUND, id);
		}
	}

	public static void requireMatchUser(Integer uid, Order order) {
		if (!Objects.equals(order.getShopId(), uid)) {
			throw new BizException(Biz403Error.ORDER_USER_NO_MATCH, uid);
		}
	}
}